const { queryAll } = require('../../database/dbUtils')
// collage数据获取渲染
const class_collageData = async (ctx: any) => {
    let sql = `select * from collage`
    let res = await queryAll(sql)
    let { college, campus, lookNum, num } = ctx.query
    let resault = res.filter((item: any) => item.college === college && item.campus === campus)
    //截取数据
    // let start = (num - 1) * lookNum
    // let end = Number(start + lookNum)
    let start = (num - 1) * lookNum;//确定循环开始的集合下标
    let end = num * lookNum;//确定循环结束的结束下标
    let arr = resault.slice(start, end)
    // console.log(arr);
    // console.log(arr.length);
    ctx.status = 200
    ctx.body = {
        code: 200,
        msg: '获取成功',
        result: { data: arr, dataLength: arr.length, resault }
    }
}
// collage 点击创建教室
const class_collageCreate = async (ctx: any) => {
    // let sql = `select * from collage`
    // let res = await queryAll(sql)
    let {
        partition,
        classCompile,
        arr,
        galleryful,
        information
    } = ctx.request.query
    // 学院  校区  其他物品多选框  容纳人数  备注
    // console.log(partition,'==',classCompile,'==',arr,'==',galleryful,'==',information);
    let campus = ''
    if (partition === '网站工程' && classCompile === '北京校区') {
        campus = 'wbj'
    } else if (partition === '网站工程' && classCompile === '保定校区') {
        campus = 'wbd'
    } else if (partition === '网站工程' && classCompile === '邯郸校区') {
        campus = 'whd'
    } else if (partition === '人工智能学院' && classCompile === '北京校区') {
        campus = 'rbj'
    } else if (partition === '人工智能学院' && classCompile === '保定校区') {
        campus = 'rbd'
    } else if (partition === '人工智能学院' && classCompile === '邯郸校区') {
        campus = 'rhd'
    } else if (partition === '传媒学院' && classCompile === '保定校区') {
        campus = 'cbd'
    } else if (partition === '传媒学院' && classCompile === '北京校区') {
        campus = 'cbj'
    } else if (partition === '传媒学院' && classCompile === '邯郸校区') {
        campus = 'chd'
    } else if (partition === '计算机学院' && classCompile === '保定校区') {
        campus = 'jbd'
    } else if (partition === '计算机学院' && classCompile === '北京校区') {
        campus = 'jbj'
    } else if (partition === '计算机学院' && classCompile === '邯郸校区') {
        campus = 'jhd'
    }
    let sql = `insert into collage(campus,classroom,college,galleryful,desks,property,chairs)values("${campus}","809","${partition}","${galleryful}","${galleryful}",'${JSON.stringify(arr)}',"${galleryful}")`
    let res = await queryAll(sql)
    // console.log(res);
    ctx.status = 200
    ctx.body = {
        code: 200,
        msg: '点击创建教室',
        result: res
    }
}
// collage点击编辑
const class_collageEdit = async (ctx: any) => {
    // let sql = `select * from collage`
    let { isId, partition, classCompile, galleryful, information } = ctx.request.query
    let campus = ''
    if (partition === '网站工程' && classCompile === '北京校区') {
        campus = 'wbj'
    } else if (partition === '网站工程' && classCompile === '保定校区') {
        campus = 'wbd'
    } else if (partition === '网站工程' && classCompile === '邯郸校区') {
        campus = 'whd'
    } else if (partition === '人工智能学院' && classCompile === '北京校区') {
        campus = 'rbj'
    } else if (partition === '人工智能学院' && classCompile === '保定校区') {
        campus = 'rbd'
    } else if (partition === '人工智能学院' && classCompile === '邯郸校区') {
        campus = 'rhd'
    } else if (partition === '传媒学院' && classCompile === '保定校区') {
        campus = 'cbd'
    } else if (partition === '传媒学院' && classCompile === '北京校区') {
        campus = 'cbj'
    } else if (partition === '传媒学院' && classCompile === '邯郸校区') {
        campus = 'chd'
    } else if (partition === '计算机学院' && classCompile === '保定校区') {
        campus = 'jbd'
    } else if (partition === '计算机学院' && classCompile === '北京校区') {
        campus = 'jbj'
    } else if (partition === '计算机学院' && classCompile === '邯郸校区') {
        campus = 'jhd'
    }
    console.log(isId, partition, classCompile, galleryful, information);
    let sql = `update collage set college="${partition}",campus="${campus}" where id="${isId}"`
    let res = await queryAll(sql)
    ctx.status = 200
    ctx.body = {
        code: 200,
        msg: '点击编辑',
        result: res
    }
}
// collage 点击删除
const class_collageDelete = async (ctx: any) => {
    let sql = `delete from collage where id = ${ctx.request.query.id}`
    let res = await queryAll(sql)
    ctx.status = 200
    ctx.body = {
        code: 200,
        msg: '点击删除',
        result: res
    }
}
// 班级管理   数据获取
const class_gradeMangerData = async (ctx: any) => {
    let sql = `select * from class`
    let res = await queryAll(sql)
    let { stage, campus, college, pageList, pageNum } = ctx.request.query
    let resault = res.filter((item: any) => item.college === college && item.campus === campus && item.level === stage)
    let start = (pageNum - 1) * pageList;//确定循环开始的集合下标
    let end = pageNum * pageList;//确定循环结束的结束下标
    let arr = resault.slice(start, end)
    ctx.status = 200
    ctx.body = {
        code: 200,
        msg: '渲染班级',
        result: { arr, length: arr.length, resault }
    }
}
// 班级管理  点击创建班级
const class_createClass = async (ctx: any) => {
    let sql = `select * from class`
    let res = await queryAll(sql)
    ctx.status = 200
    ctx.body = {
        code: 200,
        msg: '点击左侧导航',
        // result: { resault, length: resault.length }
    }
}
export {
    // 教室
    class_collageData,
    class_collageDelete,
    class_collageCreate,
    class_collageEdit,
    // 班级
    class_gradeMangerData,
    class_createClass
}